'''
Created on 17/12/2010

@author: inyaky
'''

from google.appengine.ext import db
from model.fields.uTaskField import TaskField
import datetime
import uConst

class DateTimeTaskField(TaskField):

    _value = db.DateTimeProperty()

    def getValue(self):
        return self._value
    
    def setValue(self,aValue):
        self._value=datetime.datetime.strptime(aValue, uConst.SWM_DATETIME_FORMAT)
        self.put()
        
    def toRenderable(self):
        if self._value:
            val=datetime.datetime.strftime(self.getValue(),uConst.SWM_DATETIME_FORMAT)
        else:
            val=''
            
        
        if self.getRequired():
            validators = 'required'
        else:
            validators = ''
            
        
        return [{'fname':self.getName(),'fvalue':val,'ftype':self.__class__.__name__,'fkey':self.key(), 'fvalidators':validators }]
        